package com.example.city_defense;

import java.util.ArrayList;

public class World {
	
	public static final int WORLD_WITDH = 16;
	public static final int WORLD_HEIGHT = 16;
	public static final float TICK_INITIAL = 0.05f;
	public static final float TICK_DECREMENT = 0.05f;
	float tickTime = 0;
	static float tick = TICK_INITIAL;
	
	boolean FIELD[][] = new boolean[WORLD_WITDH][WORLD_HEIGHT];
	
	public boolean gameOver = false;
	public boolean nextAttack = false;
	public int score = 0;
	public int money = 0;
	public int dificult_type;
	public int numberLevel;
	public int numberEnemy;
	public float roundTime;
	public int bonusScore;
	
	public Map map;
	public ArrayList<Weapon> weapon;
	public ArrayList<Enemy> enemy;
	
	public World(int difficultType, int mapType) {
		// TODO Auto-generated constructor stub
		map = new Map(mapType);
		/*weapon = new Weapon(7, 6, 1);
		enemy = new Enemy(map.turnPoint.get(0).x, map.turnPoint.get(0).y, 3, map);*/
		weapon = new ArrayList<Weapon>();
		enemy = new ArrayList<Enemy>();
		
		this.dificult_type = difficultType;
		switch (dificult_type) {
		case 0:{
			numberLevel = 30;
			numberEnemy = 10;
			roundTime = 2;
			bonusScore = 0;
			break;
		}
		case 1:{
			numberLevel = 40;
			numberEnemy = 15;
			roundTime = 1.5f;
			bonusScore = 25;
			break;
		}
		case 2:{
			numberLevel = 50;
			numberEnemy = 20;
			roundTime = 1;
			bonusScore = 50;
			break;
		}	
		default:
			break;
		}
		
		placeEnemy();
	}

	public void placeEnemy() {
		// TODO Auto-generated method stub
		enemy.clear();
		for (int i = 1; i <= numberEnemy; i++) {
			enemy.add(new Enemy(map.turnPoint.get(0).x, map.turnPoint.get(0).y, i, map));
		}
	}

	public void upDate(float deltaTime){
		if(gameOver)
			return;
		tickTime += deltaTime;
		while (tickTime>tick) {
			tickTime -= tick;
			//...
			if(nextAttack)
			{
				for (int i = 0; i < enemy.size(); i++) {
					if(enemy.get(i).isAlive){
						enemy.get(i).move();
						map.moveEnemy(enemy.get(i));
					}
				}
			}
			
			for (int i = 0; i < weapon.size(); i++) {
				for (int j = 0; j < enemy.size(); j++) {
					if(enemy.get(j).isAlive)
						weapon.get(i).fire(enemy.get(j));
				}
			}
		}
	}
	
}